<?php


namespace App\Repositories;


use App\Exceptions\BasicException;

class RewardDetailTypeRepository
{
    public function addRewardDetailType($rewardDetailType)
    {
        if ($rewardDetailType['id'] == 0) {
            $rewardDetailType['add_time'] = time();
            $newReward = app('model_reward_detail_type')->create($rewardDetailType);
            if ($newReward) return $newReward;
            throw new BasicException(98001);
        }
        $where[] = ['id', '=', $rewardDetailType['id']];
        $rewardDetailType['status']=1;
        $rewardDetailType['add_time']=time();
        $newReward = app('model_reward_detail_type')->where($where)->update($rewardDetailType);
        if ($newReward) return $newReward;
        throw new BasicException(98001);
    }

    public function rewardDetailTypeList($page,$perPage)
    {
        $where[] = ['status', '=', 1];
        $newReward = app('model_reward_detail_type')->where($where)
            ->orderBy('id', 'asc')->paginate($perPage, ['*'], '', $page);
        if ($newReward) return $newReward;
        throw new BasicException(98001);
    }

    public function delRewardDetailType($id)
    {
        $where[] = ['id', '=', $id];
        $rewardDetailType['status'] = 2;
        $newReward = app('model_reward_detail_type')->where($where)->update($rewardDetailType);
        if ($newReward) return $newReward;
        throw new BasicException(98001);
    }

}
